package com.example.onlinejudge.controller;

import com.example.onlinejudge.mapper.ProblemMapper;
import com.example.onlinejudge.model.Problem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class ProblemController {
    @Autowired
    private ProblemMapper problemMapper;
    @RequestMapping("/problem")
    public List<Problem> getProblem(Integer id){
        List<Problem> problems=new ArrayList<>();
        if(id==null||id.equals("")){
            problems.addAll(problemMapper.selectAll());
        }else{
            problems.add(problemMapper.selectOne(id));
        }
        return problems;
    }
}
